package me.zk.practice1.s;

import java.util.Arrays;

public class LS875 {

    public static int minEatingSpeed(int[] piles, int h) {
        Arrays.sort(piles);
        int min = 1;
        int max = piles[piles.length-1];

        while (min < max) {
            int mid = (max-min)/2 + min;
            if (get(piles,mid) > h) {
                min = mid+1;
            } else {
                max = mid;
            }

        }
        return min;
    }

    public static int get(int[] piles, int mid) {

        int count = 0;
        for (int n : piles) {
            count += (n + mid -1)/mid;
        }

        return count;
    }

    public static void main(String[] args) {
        minEatingSpeed(new int[]{312884470},312884469);
    }
}
